//package com.liqi.frame.comm.exception;
//
//import cn.hutool.log.Log;
//import cn.hutool.log.LogFactory;
//import com.liqi.frame.comm.dto.HttpResult;
//import com.liqi.frame.comm.enums.ResultEnum;
//import com.liqi.frame.comm.util.AjaxUtil;
//import com.liqi.frame.comm.util.ShiroUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.shiro.SecurityUtils;
//import org.apache.shiro.authz.UnauthenticatedException;
//import org.springframework.stereotype.Component;
//import org.springframework.web.servlet.ModelAndView;
//import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
///**
// * 全局异常类
// * @author liqi on 2017/8/4.
// */
//@Component
//@Slf4j
//public class GlobalExceptionResolver extends SimpleMappingExceptionResolver {
////    private static final Log log = LogFactory.get();
//
//    @Override
//    protected ModelAndView doResolveException(HttpServletRequest request,
//                                              HttpServletResponse response, Object handler, Exception ex){
//
//        if (!ShiroUtil.getSubject().isAuthenticated()) {
////            session过期
//            if (AjaxUtil.isAjax(request)) {
//
//                HttpResult result = new HttpResult(ResultEnum.FAILURE, ex.getMessage());
//                if (ex instanceof UnauthenticatedException) {
//                    result.setMsg("UnauthenticatedException");
//                }
//                AjaxUtil.out(response, result);
//                return null;
//            } else if (ex instanceof SsoException) {
//                try {
//                    throw ex;
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            } else {
////                try {
//                    throw new GlobalException(ResultEnum.LOGON_EXPIRATION);
////                } catch (NotLoginException e) {
////                    e.printStackTrace();
////                }
////                return getModelAndView("comm/exception/loginException", ex, request);
//            }
//        }
//
//        String viewName = determineViewName(ex,request);
//        response.setCharacterEncoding("UTF-8");
////        if (viewName != null) {// JSP格式返回
//            if (!AjaxUtil.isAjax(request)) {
//                // 如果不是ajax请求
//                Integer statusCode = determineStatusCode(request, viewName);
//                if (statusCode != null) {
//                    applyStatusCodeIfPossible(request, response, statusCode);
//                }
//                return getModelAndView(viewName, ex, request);
//            } else {
//                // 如果是ajax请求
//                HttpResult result = new HttpResult(ResultEnum.FAILURE, ex.getMessage());
//                AjaxUtil.out(response, result);
//
//                log.info("",ex);
//                return null;
//            }
////        } else {
////            return null;
////        }
//    }
//}
